package com.office.system.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.system.domain.SysUsage;
import com.office.system.service.ISysUsageService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 领用管理Controller
 *
 * @author xyq
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/system/usage")
public class SysUsageController extends BaseController {
    @Autowired
    private ISysUsageService sysUsageService;

    /**
     * 查询领用管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:usage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUsage sysUsage) {
        startPage();
        List<SysUsage> list = sysUsageService.selectSysUsageList(sysUsage);
        return getDataTable(list);
    }

    /**
     * 导出领用管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:usage:export')")
    @Log(title = "领用管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUsage sysUsage) {
        List<SysUsage> list = sysUsageService.selectSysUsageList(sysUsage);
        ExcelUtil<SysUsage> util = new ExcelUtil<SysUsage>(SysUsage.class);
        util.exportExcel(response, list, "领用管理数据");
    }

    /**
     * 获取领用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:usage:query')")
    @GetMapping(value = "/{usageId}")
    public AjaxResult getInfo(@PathVariable("usageId") Long usageId) {
        return success(sysUsageService.selectSysUsageByUsageId(usageId));
    }


    /**
     * 新增领用管理
     */
    @PreAuthorize("@ss.hasPermi('system:usage:add')")
    @Log(title = "领用管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUsage sysUsage) {
        sysUsage.setUsageDate(new Date());
        return toAjax(sysUsageService.insertSysUsage(sysUsage));
    }

    /**
     * 修改领用管理
     */
    @PreAuthorize("@ss.hasPermi('system:usage:edit')")
    @Log(title = "领用管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUsage sysUsage) {
        return toAjax(sysUsageService.updateSysUsage(sysUsage));
    }

    /**
     * 删除领用管理
     */
    @PreAuthorize("@ss.hasPermi('system:usage:remove')")
    @Log(title = "领用管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{usageIds}")
    public AjaxResult remove(@PathVariable Long[] usageIds) {
        return toAjax(sysUsageService.deleteSysUsageByUsageIds(usageIds));
    }


    /**
     * 获取个人领用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:usage:query')")
    @GetMapping(value = "/people/{usagePeople}")

    public AjaxResult getInfoPeople(@PathVariable("usagePeople") String usagePeople) {
        System.out.println(usagePeople);
        return success(sysUsageService.selectSysUsageByUsagePeople(usagePeople));

    }
}
